package yt.kpool.adapter;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.king.base.adapter.ViewHolderRecyclerAdapter;
import com.king.base.adapter.holder.ViewHolder;
import java.util.List;
import yt.kpool.R;
import yt.kpool.bean.RebateSettlementBean;
import yt.kpool.util.ToastUtil;
import yt.kpool.util.Util;

public class RebateSettlementAdapter extends ViewHolderRecyclerAdapter<RebateSettlementBean.DataBean> {

     private AppCompatActivity context;


    public RebateSettlementAdapter(Context context, List<RebateSettlementBean.DataBean> listData) {
        super(context, listData);
        this.context=(AppCompatActivity)context;
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, int viewType) {
        return layoutInflater.inflate(R.layout.adapter_rebatesettlement,null);
    }


    @Override
    public void bindViewDatas(ViewHolder holder, RebateSettlementBean.DataBean dataBean, int position) {
        final TextView tv_address=holder.getView(R.id.tv_address);
        final TextView tv_txid=holder.getView(R.id.tv_txid);
        holder.setText(R.id.tv_pay,Util.Knumber(dataBean.getAmount()));
        holder.setText(R.id.tv_time, dataBean.getCreatedTime());
        holder.setText(R.id.tv_address,dataBean.getAddress());
        holder.setText(R.id.tv_txid,dataBean.getHash());

        tv_address.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                copyTextToClipboard(tv_address.getText().toString());
                return false;
            }
        });

        tv_txid.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                copyTextToClipboard(tv_txid.getText().toString());
                return false;
            }
        });

    }

    public void copyTextToClipboard(final String text) {
        context.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                ClipboardManager clipboardManager = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clipData = ClipData.newPlainText("content", text);
                clipboardManager.setPrimaryClip(clipData);
                ToastUtil.showToast(context,"复制成功");
            }
        });
    }
}
